from pyecharts.charts import Page
import pandas as pd
import sys
sys.path.append("..//database")
from SqlWizard import *
from CmnFuncs import *

def run_other_agris():
    '''
    本模块包含品种：鸡蛋，白糖，棉花
    设计图表：
    1. 鸡蛋现货基差表；
    2. 鸡蛋月差表；
    3. 棉花现货基差表；
    4. 棉花月差表；
    5. 白糖现货基差表；
    6. 白糖月差表；
    7. 白糖 / 原油 主力比价

    '''

    a_list = date_checker_1()

    sc_main = read_sql_fut('fut_scl')

    jd_spot = read_sql_spot('spot_jd')
    jd_index = read_sql_fut_index('fut_index_jd')
    jd_ry = read_sql_ry('roll_yield_jd')
    jd_spdrdx = read_sql_spdrdx('spdrdex_jd')
    jd_1 = read_sql_fut('fut_jd{}'.format(a_list[0]))
    jd_2 = read_sql_fut('fut_jd{}'.format(a_list[1]))
    jd_3 = read_sql_fut('fut_jd{}'.format(a_list[2]))

    cf_spot = read_sql_spot('spot_cf')
    cf_index = read_sql_fut_index('fut_index_cf')
    cf_ry = read_sql_ry('roll_yield_cf')
    cf_spdrdx = read_sql_spdrdx('spdrdex_cf')
    cf_1 = read_sql_fut('fut_cf{}'.format(a_list[0]))
    cf_2 = read_sql_fut('fut_cf{}'.format(a_list[1]))
    cf_3 = read_sql_fut('fut_cf{}'.format(a_list[2]))

    sr_spot = read_sql_spot('spot_sr')
    sr_index = read_sql_fut_index('fut_index_sr')
    sr_ry = read_sql_ry('roll_yield_sr')
    sr_spdrdx = read_sql_spdrdx('spdrdex_sr')
    sr_1 = read_sql_fut('fut_sr{}'.format(a_list[0]))
    sr_2 = read_sql_fut('fut_sr{}'.format(a_list[1]))
    sr_3 = read_sql_fut('fut_sr{}'.format(a_list[2]))

    # 鸡蛋
    header_jd = draw_separator('鸡蛋')
    # 鸡蛋远期曲线
    future_curve_jd = draw_future_curve_jd(jd_spot, jd_1, jd_2, jd_3)
    # 鸡蛋一致性预期指标
    idctr_jd = draw_spec_idctr('鸡蛋', jd_spdrdx, jd_index, jd_ry)
    # 1. 鸡蛋现货基差表；
    jd_spot_chart = draw_spot_spd_jd('鸡蛋', jd_spot)
    # 鸡蛋合约价格、成交量、持仓量、持仓量变化图
    jd_contract_1 = draw_contract('jd{}'.format(a_list[0]), jd_1)
    jd_contract_2 = draw_contract('jd{}'.format(a_list[1]), jd_2)
    jd_contract_3 = draw_contract('jd{}'.format(a_list[2]), jd_3)
    # 2. 鸡蛋月差表；
    jd_12_chart = draw_spd('jd{}'.format(a_list[0]), jd_1['close'], 'jd{}'.format(a_list[1]), jd_2['close'])
    jd_23_chart = draw_spd('jd{}'.format(a_list[1]), jd_2['close'], 'jd{}'.format(a_list[2]), jd_3['close'])

    # 棉花
    header_cf = draw_separator('棉花')
    # 棉花远期曲线
    future_curve_cf = draw_future_curve(cf_spot, cf_1, cf_2, cf_3)
    # 棉花一致性预期指标
    idctr_cf = draw_spec_idctr('棉花', cf_spdrdx, cf_index, cf_ry)
    # 3. 棉花现货基差表；
    cf_spot_chart = draw_spot_spd('棉花', cf_spot)
    # 棉花合约价格、成交量、持仓量、持仓量变化图
    cf_contract_1 = draw_contract('cf{}'.format(a_list[0]), cf_1)
    cf_contract_2 = draw_contract('cf{}'.format(a_list[1]), cf_2)
    cf_contract_3 = draw_contract('cf{}'.format(a_list[2]), cf_3)
    # 4. 棉花月差表；
    cf_12_chart = draw_spd('cf{}'.format(a_list[0]), cf_1['close'], 'cf{}'.format(a_list[1]), cf_2['close'])
    cf_23_chart = draw_spd('cf{}'.format(a_list[1]), cf_2['close'], 'cf{}'.format(a_list[2]), cf_3['close'])

    # 白糖
    header_sr = draw_separator('白糖')
    # 白糖远期曲线
    future_curve_sr = draw_future_curve(sr_spot, sr_1, sr_2, sr_3)
    # 白糖一致性预期指标
    idctr_sr = draw_spec_idctr('白糖', sr_spdrdx, sr_index, sr_ry)
    # 5. 白糖现货基差表；
    sr_spot_chart = draw_spot_spd('白糖', sr_spot)
    # 白糖合约价格、成交量、持仓量、持仓量变化图
    sr_contract_1 = draw_contract('sr{}'.format(a_list[0]), sr_1)
    sr_contract_2 = draw_contract('sr{}'.format(a_list[1]), sr_2)
    sr_contract_3 = draw_contract('sr{}'.format(a_list[2]), sr_3)
    # 6. 白糖月差表；
    sr_12_chart = draw_spd('sr{}'.format(a_list[0]), sr_1['close'], 'sr{}'.format(a_list[1]), sr_2['close'])
    sr_23_chart = draw_spd('sr{}'.format(a_list[1]), sr_2['close'], 'sr{}'.format(a_list[2]), sr_3['close'])

    # 品种间
    header_cross = draw_separator('品种间')
    # 7. 白糖 / 原油 主力比价
    ratio_sr_sc = draw_price_ratio('白糖指数', sr_index['close'], '原油主连', sc_main['close'], 2)
    arbi_record('sr', sr_index['close'], 'sc', sc_main['close'], x=1, y=1, opt=1, cat=1)

    page = Page(page_title='其他农副', layout=Page.SimplePageLayout)
    page.add(
        header_jd,
        future_curve_jd,
        idctr_jd,
        jd_spot_chart,
        jd_contract_1,
        jd_contract_2,
        jd_contract_3,
        jd_12_chart,
        jd_23_chart,
        header_cf,
        future_curve_cf,
        idctr_cf,
        cf_spot_chart,
        cf_contract_1,
        cf_contract_2,
        cf_contract_3,
        cf_12_chart,
        cf_23_chart,
        header_sr,
        future_curve_sr,
        idctr_sr,
        sr_spot_chart,
        sr_contract_1,
        sr_contract_2,
        sr_contract_3,
        sr_12_chart,
        sr_23_chart,
        header_cross,
        ratio_sr_sc,
    )
    page.render('其他农副.html')

